package cn.hxlc.tie.demo.modular.work.service.impl;
/*
 @author rui
 @date 2021/7/29 --21:22
*/

import cn.hutool.core.bean.BeanUtil;
import cn.hxlc.tie.demo.modular.work.entity.WorkShopEntity;
import cn.hxlc.tie.demo.modular.work.mapper.WorkshopEntityMapper;
import cn.hxlc.tie.demo.modular.work.model.param.WorkShopEntityParam;
import cn.hxlc.tie.demo.modular.work.model.result.WorkShopEntityResult;
import cn.hxlc.tie.demo.modular.work.service.WorkShopEntityService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

@Service
@Transactional
public class WorkShopEntityServiceImpl extends ServiceImpl<WorkshopEntityMapper, WorkShopEntity> implements WorkShopEntityService {
    @Override
    public void update(WorkShopEntityParam workShopEntityParam) {
        WorkShopEntity entity=getEntity(workShopEntityParam);
        WorkShopEntity oldEntity=getOldEntity(workShopEntityParam);
        BeanUtil.copyProperties(entity,oldEntity);
        this.baseMapper.updateById(oldEntity);

    }

    @Override
    public WorkShopEntity detail(Long fid) {
        return this.baseMapper.selectById(fid);
    }

    @Override
    public Boolean deteleOne(Long fid) {
        return this.baseMapper.deleteById(fid)>0;
    }

    @Override
    public void add(WorkShopEntityParam workShopEntityParam) {
        WorkShopEntity entity=getEntity(workShopEntityParam);
        this.baseMapper.addEntity(workShopEntityParam);
    }

    @Override
    public List<WorkShopEntityResult> findListBySpec(WorkShopEntityParam entry) {
        return this.baseMapper.findListBySpec(entry);
    }

    public WorkShopEntity getEntity(WorkShopEntityParam workShopEntityParam){
        WorkShopEntity entity=new WorkShopEntity();
        BeanUtil.copyProperties(workShopEntityParam,entity);
        return entity;
    }
    public Long getKey(WorkShopEntityParam param){
        return param.getFid();
    }
    public WorkShopEntity getOldEntity(WorkShopEntityParam param){
       return this.getById(param.getFid());
    }


}
